import Vue from 'vue'
import Router from 'vue-router'
// import { tranListTotreeList } from '@/utils'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// import BlankLayout from '@/layout/BlankLayout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'el-icon-s-home', affix: true, roles: ['admin', 'member'] }
      }
    ]
  },
  {
    path: '/masterTable',
    component: Layout,
    children: [
      {
        path: 'masterTable',
        component: () => import('@/views/ManagementSystem/masterTable'),
        name: 'masterTable',
        meta: { title: '主表列表', icon: 'el-icon-tickets', affix: false, roles: ['admin', 'member'] }
      }
    ]
  },
  {
    path: '/externalApi',
    component: Layout,
    children: [
      {
        path: 'externalApi',
        component: () => import('@/views/ManagementSystem/externalApi'),
        name: 'externalApi',
        meta: { title: '外部接口列表', icon: 'el-icon-mobile-phone', affix: false, roles: ['admin', 'member'] }
      }
    ]
  },
  {
    path: '/subTableBackups',
    component: Layout,
    children: [
      {
        path: 'subTableBackups',
        component: () => import('@/views/ManagementSystem/subTableBackups'),
        name: 'subTableBackups',
        meta: { title: '备份列表', icon: 'el-icon-document-copy', affix: false, roles: ['admin', 'member'] }
      }
    ]
  },
  {
    path: '/newTable',
    component: Layout,
    children: [
      {
        path: 'newTable',
        component: () => import('@/views/ManagementSystem/newTable'),
        name: 'newTable',
        meta: { title: '新表', icon: 'el-icon-s-cooperation', affix: false, roles: ['admin', 'member'] }
      }
    ]
  }
]

export const asyncRoutes = []

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
